package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.services.infrastructure.bean.RecycleCarsBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.RecycleCarsMapper;
import com.molichuxing.services.infrastructure.dto.request.create.RecycleCarsCreateDto;
import com.molichuxing.services.infrastructure.dto.response.RecycleCarsDto;
import com.molichuxing.services.infrastructure.service.RecycleCarsService;
import com.molichuxing.services.property.RecycleStateEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author zoumingyu
 * @Date 2020年07月29日
 */
@Service("recycleCarsService")
public class RecycleCarsServiceImpl implements RecycleCarsService {

    @Resource
    private RecycleCarsMapper recycleCarsMapper;


    @Override
    public boolean create(RecycleCarsCreateDto createDto) {
        return recycleCarsMapper.create(Convert.toRecycleCarsBean(createDto)) > 0;
    }

    @Override
    public List<RecycleCarsDto> getRecycleCars(Long orderCode) {
        return Convert.toRecycleCarsDto(recycleCarsMapper.getRecycleCars(orderCode, null));
    }

    @Override
    public RecycleCarsDto getRecycleCars(Long orderCode, RecycleStateEnum recycleState) {
        List<RecycleCarsBean> getRecycleCars = recycleCarsMapper.getRecycleCars(orderCode, recycleState.getValue());
        if (getRecycleCars == null || getRecycleCars.isEmpty()) {
            return null;
        }

        return Convert.toRecycleCarsDto(getRecycleCars.get(0));
    }

    @Override
    public int getRecycleCarsTotal() {
        return (int) recycleCarsMapper.getRecycleCarsTotal();
    }
}
